home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / proport.zip / PROPORT.A86 < prev    next >
Text File  |  1989-08-05  |  19KB  |  930 lines

  1. ;    PROPORT    Editor port program for PROCOMM.  Supports aliases, etc.
  2.  
  3. ;    Usage:    proport    (no arguments)
  4. ;            Prompt the user for a DOS command, and execute it.
  5.  
  6. ;        proport >file
  7. ;            List the aliases to that file.
  8.  
  9. ;        proport <file
  10. ;            Load the aliases from that file.  The program
  11. ;            PROPORT.COM should have been run from the current
  12. ;            directory, and should not be write protected.
  13.  
  14. ;    Aliases are of the form xx=yyy zz, one per line.  A comment line may
  15. ;    begin with a semicolon.  Leading spaces are also ignored.  If the first
  16. ;    part of the command line matches the alias, then the part to the right
  17. ;    is substituted.  If the command line begins with an `at' symbol (`@'),
  18. ;    or if the called program terminates with an error condition, then
  19. ;    PROPORT will issue a `wolf-whistle' (courtesy of SDF.COM).
  20.  
  21. ;    This program supports pipes, redirection, and internal and external
  22. ;    commands.  It calls internal commands by calling COMMAND.COM with the /C
  23. ;    switch and calls external commands directly, so that their exit codes
  24. ;    can be returned.  (COMMAND.COM does not return exit codes, so internal
  25. ;    commands will never return an exit code.)
  26.  
  27. ;    Much of this code is already present in some form in COMMAND.COM; it
  28. ;    would have been much easier if this had been available as a subfunction
  29. ;    of the EXEC call.  Ahem.  :-( .
  30.  
  31. ;    Assemble with A86.
  32.  
  33. TAB    equ    9
  34. LF    equ    10
  35. CR    equ    13
  36. CPMEOF    equ    26
  37.  
  38. ;    Addresses in high memory.
  39.  
  40. envseg    equ    2ch        ;segment of environment
  41. fcb1    equ    5ch        ;first FCB to put in new process
  42. fcb2    equ    6ch        ;second ...
  43. strs    equ    85h        ;start+5 of area to store various strings
  44.  
  45.     jmp    start        ;jump to start of code
  46.     db    0,0        ;five padding bytes
  47.  
  48. ;    Data area.
  49.  
  50. block    dw    0,0,0,fcb1,0,fcb2,0    ;parameter block for EXEC call
  51.  
  52. pipe1    db    '_:/%PIPE1.$$$',0
  53. zero    equ    pipe1+13
  54. pipe2    db    '_:/%PIPE2.$$$',0
  55.  
  56. intcmds    db    'BREAK',0,'CD',0,'CHDIR',0,'CLS',0,'COPY',0,'CTTY',0,'DATE',0
  57.     db    'DEL',0,'DIR',0,'ECHO',0,'ERASE',0,'EXIT',0,'FOR',0,'GOTO',0
  58.     db    'IF',0,'MD',0,'MKDIR',0,'PATH',0,'PAUSE',0,'PROMPT',0,'RD',0
  59.     db    'REM',0,'REN',0,'RENAME',0,'RMDIR',0,'SET',0,'SHIFT',0,'TIME',0
  60.     db    'TYPE',0,'VER',0,'VERIFY',0,'VOL',0,0
  61.  
  62. dosver    db    0        ;DOS version
  63. swchar    db    0        ;switch character (usually '/')
  64. innam    dw    0        ;address of string of '<' file
  65. pipnam    dw    0        ;address of string of pipe file
  66. outnam    dw    0        ;address of string of '>' file
  67. appflg    db    0        ;nonzero if '>>' was used
  68. delflg    db    0        ;nonzero if input file is to be deleted
  69. inhndl    db    -1        ;internal handle for orig. stdin
  70. outhndl    db    -1        ;internal handle for orig. stdout
  71. next    dw    0        ;next pipe to process
  72. bgnpath    dw    0        ;address of first char. of path name
  73. bgnfil    dw    0        ;addr of first char. of filename proper
  74. endfil    dw    0        ;addr of last char. of filename proper
  75. envpos    dw    0        ;current position in path string in environment
  76. pathaddr dw    0        ;address of PATH environment variable
  77. cmdaddr    dw    0        ;address of COMSPEC variable
  78. whflag    db    0        ;nonzero for whistle
  79. whtime    dw    100        ;timing constant (default 100 if patched)
  80.  
  81. ;    Begin permanent part of code.
  82.  
  83. sy10:    mov    sp,offset end1+200
  84.     int    21h        ;shrink used memory
  85.  
  86. ;    Begin execution loop.
  87. ;    At this point si = address of next command.
  88.  
  89. sy11:    mov    di,si        ;find end of current string
  90.     mov    al,0
  91.     mov    cx,-1
  92.     repnz    scasb
  93.     mov    dx,innam
  94.     or    dx,dx
  95.     jz    sy12        ;if no input file given
  96.  
  97. ;    Open input file.
  98.  
  99.     mov    ax,3d00h    ;open for reading
  100.     int    21h
  101.     jc    sy12a        ;if error
  102.     xchg    ax,bx
  103.     mov    al,-1        ;force it into handle 0
  104.     xchg    al,[bx+18h]
  105.     xchg    al,[18h]
  106.     mov    inhndl,al
  107.  
  108. ;    Open output or pipe file.
  109.  
  110. sy12:    cmp    byte [di],0
  111.     jne    sy13        ;if we are piping
  112.     mov    dx,outnam
  113.     mov    pipnam,dx
  114.     or    dx,dx
  115.     jz    sy18        ;if no output redirection
  116.     cmp    byte appflg,0
  117.     jz    sy15        ;if no appending
  118.     mov    ax,3d01h    ;open for writing
  119.     int    21h
  120.     jc    sy12a
  121.     xchg    ax,bx
  122.     mov    ax,4202h    ;LSEEK
  123.     xor    cx,cx
  124.     xor    dx,dx
  125.     int    21h
  126.     jmp    short sy17
  127.  
  128. sy12a:    mov    dx,offset msg1    ;error opening I/O redirection file
  129.     jmp    err
  130.  
  131. ;    Open pipe file.
  132.  
  133. sy13:    mov    dx,offset pipe1
  134.     cmp    dx,innam
  135.     jne    sy14        ;if not duplicate
  136.     mov    dx,offset pipe2
  137. sy14:    mov    pipnam,dx
  138.     cmp    byte dosver,2
  139.     je    sy15        ;if DOS 2
  140.     mov    ah,5ah        ;create unique file
  141.     mov    bx,dx
  142.     mov    byte [bx+3],0
  143.     jmp    short sy16
  144.  
  145. sy15:    mov    ah,3ch        ;create file
  146. sy16:    xor    cx,cx        ;attribute
  147.     int    21h
  148.     xchg    ax,bx
  149.     jnc    sy17        ;if no error
  150.     mov    dx,offset msg2    ;cannot open pipe
  151. errj1:    jmp    err
  152.  
  153. sy17:    mov    al,-1        ;move it to handle #1
  154.     xchg    al,[bx+18h]
  155.     xchg    al,[19h]
  156.     mov    outhndl,al
  157.  
  158. sy18:    mov    next,di
  159.  
  160. ;    Process the input line.  At this point si points to the beginning of the
  161. ;    current line and di to the next.
  162.  
  163. ;    Check for:    1.  Drive change.
  164. ;            2.  Internal command.
  165. ;            3.  External command with explicit drive or path.
  166. ;            4.  External command.
  167.  
  168.     push    si
  169.     mov    dl,swchar
  170.     mov    ax,2900h    ;parse filename
  171.     mov    di,fcb1
  172.     int    21h
  173.     or    al,al
  174.     mov    dx,offset msg3    ;invalid drive
  175.     js    errj1
  176.     mov    dx,offset msg4    ;bad command or file name
  177.     jnz    errj1
  178.     cmp    byte [di],0
  179.     je    sy19        ;if no drive given
  180.     cmp    byte [di+1],' '
  181.     jne    sy24        ;if part of filename given
  182.     mov    al,[si]
  183.     call    ifslash
  184.     je    sy24        ;if slash, then part of a filename is here
  185.  
  186. ;    Change current drive.
  187.  
  188.     mov    ah,0eh        ;select disk
  189.     mov    dl,[di]
  190.     dec    dx
  191.     int    21h
  192.     jmp    done        ;done
  193.  
  194. ;    Check for internal command.
  195.  
  196. sy19:    mov    al,[si]
  197.     call    ifslash
  198.     jne    sy20        ;if not a slash, then this is not option 3.
  199.     inc    byte [di]
  200. sy20:    mov    di,offset intcmds
  201.     mov    al,0
  202.  
  203. sy21:    cmp    al,[di]
  204.     je    sy24        ;if end of list
  205.     mov    cx,8
  206.     mov    si,fcb1+1
  207.     repe    cmpsb
  208.     dec    di
  209.     cmp    byte [si-1],' '
  210.     jne    sy22        ;if unequal
  211.     scasb
  212.     je    sy23        ;if [di]=0, then they match
  213. sy22:    repnz    scasb        ;skip to next string
  214.     jmp    sy21
  215.  
  216. ;    Process internal command.
  217.  
  218. sy23:    pop    si
  219.     sub    si,4
  220.     mov    di,si
  221.     mov    al,' '        ;prepend " /C "
  222.     mov    ah,swchar
  223.     stosw
  224.     mov    ax,' C'
  225.     stosw
  226.     call    do80h
  227.     mov    ax,4b00h    ;EXEC
  228.     mov    dx,cmdaddr
  229.     mov    ds,[envseg]
  230.     mov    bx,offset block
  231.     int    21h
  232.     cld
  233.     mov    bx,cs
  234.     mov    ss,bx
  235.     mov    sp,offset end1+200
  236.     mov    ds,bx
  237.     mov    es,bx
  238.     mov    dx,offset msg5    ;cannot load COMMAND.COM
  239.     if c jmp err
  240. donej1:    jmp    done
  241.  
  242. ;    Process external command.  At this point, the start address of the
  243. ;    string is on top of the stack, and the first byte of FCB1 is zero if
  244. ;    paths are to be searched.
  245.  
  246. sy24:    mov    di,offset zero
  247.     cmp    byte [fcb1],0
  248.     jnz    sy25        ;if drive or path given
  249.     mov    di,pathaddr
  250. sy25:    pop    si        ;start of string
  251.     mov    envpos,di    ;save environment position
  252.     call    len2sep
  253.     mov    di,offset end1+80
  254.     sub    di,cx
  255.     mov    bgnfil,di    ;beginning of file name
  256.     mov    bgnpath,di
  257.     rep    movsb        ;move filename over
  258.     mov    endfil,di    ;end of file name
  259.  
  260. ;    Set up FCB's & parameter string.
  261.  
  262.     push    si
  263.     call    swskip        ;skip switches
  264.     mov    ax,2901h    ;parse filename
  265.     mov    di,fcb1
  266.     int    21h
  267. sy26:    lodsb            ;skip till separator
  268.     cmp    al,dl
  269.     je    sy27        ;if switchar
  270.     cmp    al,0
  271.     je    sy27        ;if end
  272.     call    ifsep
  273.     jne    sy26        ;if not separator
  274. sy27:    dec    si
  275.     call    swskip
  276.     mov    ax,2901h    ;parse filename
  277.     mov    di,fcb2
  278.     int    21h
  279.     pop    si        ;back to start of string
  280.     call    do80h        ;do parameter string
  281.  
  282. ;    Loop over paths.  At this point, the path is prepended to the file name
  283. ;    and bgnpath is set accordingly.  ds=es=ss=cs.
  284.  
  285. sy28:    mov    di,endfil    ;add .COM
  286.     mov    ax,'C.'
  287.     stosw
  288.     mov    ax,'MO'
  289.     stosw
  290.     mov    al,0
  291.     stosb
  292.  
  293. sy29:    mov    ax,4b00h    ;EXEC
  294.     mov    bx,offset block
  295.     mov    dx,bgnpath
  296.     int    21h
  297.     cld
  298.     mov    bx,cs
  299.     mov    ss,bx
  300.     mov    sp,offset end1+200
  301.     mov    ds,bx
  302.     mov    es,bx
  303.     jnc    donej1        ;if done
  304.     cmp    ax,2
  305.     jne    err0        ;if error other than file not found
  306.     and    sp,-2
  307.     mov    di,endfil
  308.     inc    di
  309.     cmp    byte [di],'C'
  310.     jne    sy30        ;if we just did .EXE
  311.     mov    ax,'XE'
  312.     stosw
  313.     stosb
  314.     jmp    sy29        ;go back and try .EXE
  315.  
  316. ;    Try another path.
  317.  
  318. sy30:    mov    si,envpos    ;environment position
  319.     mov    ds,[envseg]
  320.     call    skipsep
  321.     cmp    al,0
  322.     mov    dx,offset msg4    ;bad command or file name
  323.     je    err        ;if no more paths
  324.     mov    cx,si        ;get length of next path
  325. sy31:    lodsb
  326.     cmp    al,0
  327.     je    sy32        ;if end of string
  328.     call    ifsep
  329.     jne    sy31        ;if not separator
  330. sy32:    dec    si
  331.     mov    cs:envpos,si
  332. sy33:    dec    si
  333.     cmp    byte [si],'/'
  334.     je    sy33        ;skip trailing slashes
  335.     cmp    byte [si],'\'
  336.     je    sy33        ;skip trailing slashes
  337.     inc    si
  338.     xchg    cx,si
  339.     sub    cx,si        ;cx = length
  340.     mov    di,cs:bgnf